<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/layui/css/layui.css"/>
    <link href="/layui/css/modules/layer/default/layer.css" rel="stylesheet"/>
    <link rel="stylesheet" href="/css/index.css"/>
</head>
<body class="main-body-admin">
<nav style="margin-top: 10px;">
    <select id="classGroupId" onchange="showStudent()">
        <option value="DEFAULT"></option>
    </select>
    <button class="layui-btn" onclick="process()">查看进度</button>
    <input class="layui-input-inline" id="searchValue"/>
    <button class="layui-btn layui-btn-normal" onclick="search()">搜索</button>
</nav>
<table id="student" lay-filter="test"></table>
<script src="/js/jquery.min.js"></script>
<script src="/js/config/server.js"></script>
<script src="/js/common/login.js"></script>
<script src="/js/common/upload.js"></script>
<script src="/layui/layui.all.js"></script>
<script>
  var table;
  var majorId;
  var classGroupId;

  checkRole('teacher');
  // 加载学院
  handlerGet('/rest/teacher/'+sessionStorage.getItem('teacherId'), 'teacher', function (data) {

    majorId = data.data.majorId;
    handlerGet('/rest/classGroup/listTotalByMajor/' + majorId, 'teacher', function (data) {
      $("#classGroupId").html('<option value="DEFAULT"></option>');
      data.data.forEach(function (item) {
        $("#classGroupId").append('<option value="' + item.groupId + '">' + item.name + '</option>');
      });
    });
  }, function (data) {
    layer.msg('加载学院失败，请检查网络' + data.responseText)
  });

  function showStudent() {
    classGroupId = $("#classGroupId").val();
    if (majorId !== 'DEFAULT') {
      layui.use('table', function () {
        table = layui.table;
        table.render({
          elem: '#student'
          , height: 515
          , url: host + '/rest/student/listByClassGroup/' + classGroupId //数据接口
          , page: true //开启分页
          , limit: 15
          , limits: [15, 30, 45]
          , cols: [[ //表头
            {checkbox: true},
            {field: 'studentNo', title: '学号', width: 120, sort: true}
            , {field: 'username', title: '姓名', width: 120}
            , {field: 'password', title: '密码', width: 120}
            , {field: 'email', title: '邮箱', width: 120}
            , {field: 'year', title: '届数', width: 120}
            , {field: 'openId', title: 'openId', width: 120}
            , {field: 'studentId', title: 'ID', width: 120, sort: true}
          ]]
        });
      });
    }
  }

  function search() {
    if ($("#majorId").val() === 'DEFAULT') {
      layer.msg('请选择具体的专业')
    } else {
      var value = $("#searchValue").val();
      if (value === '' || value === ' ') {
        layer.msg('请输入查询参数');
        return;
      }
      layui.use('table', function () {
        var table = layui.table;
        table.reload('student', {
          url: host + '/rest/student/search/' + classGroupId + '?name=' + value + ''
          , where: {}
        });
      })
    }
  }

  function process() {
    var checkStatus = table.checkStatus('student');
    if (checkStatus.data.length !== 1) {
      layer.msg('请选择一条记录');
    } else {
      // layer.msg(checkStatus.data[0].studentId);
      sessionStorage.setItem('dataFlowTopicId', checkStatus.data[0].studentId);
      frameTip('查看课题流程状态 [ 自顶向下的流程 ]', '../module/topicProcess.html')

    }
  }

  function frameTip(title, url) {
    layer.open({
      title: title
      , type: 2
      , content: url
      , btnAlign: 'c'
      , resize: true
      , tipsMore: true
      , area: ['1000px', '500px']
      ,cancel: function () {
        sessionStorage.removeItem('dataFlowTopicId');
      }
    });
  }
</script>
<script id="editData" type="text/html">
    <div id="Tips">
        <label for="studentNo">学号</label>
        <input name="studentNo" type="text" id="studentNo" value="studentNo##VA" required/><br/>
        <label for="username">姓名</label>
        <input name="username" type="text" id="username" value="username##VA" required/><br/>
        <label for="password">密码</label>
        <input name="password" type="text" id="password" value="password##VA" required/><br/>
        <label for="email">邮箱</label>
        <input name="email" type="text" id="email" value="email##VA" required/><br/>
        <label for="year">届数</label>
        <input name="year" type="text" id="year" value="year##VA" required/><br/>
        <label for="openId">微信</label>
        <input name="openId" type="text" id="openId" value="openId##VA" required/>
    </div>
</script>

<script id="loadFromExcel" type="text/html">
    <div>
        <input type="file" id="selectFile"/>
        <progress id="progressBar" value="0" max="100"></progress>
        <span id="percentage"></span>
    </div>
</script>
</body>
</html>